package com.xxd.spring.boot.demo.wubolin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.wubolin.Result;
import com.xxd.spring.boot.demo.wubolin.entity.Curriculum;
import com.xxd.spring.boot.demo.wubolin.exception.MyException;
import com.xxd.spring.boot.demo.wubolin.service.CurriculumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/curriculum")
public class CurriculumController {
    @Autowired
    private CurriculumService curriculumService;
    @RequestMapping("/add")
    public Result add(@RequestBody Curriculum curriculum) throws MyException {
        curriculumService.add(curriculum);
        return new Result().success();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Curriculum curriculum) throws MyException {
        curriculumService.update(curriculum);
        return new Result().success();
    }

    @RequestMapping("/delete{id}")
    public Result detele(@PathVariable Integer id) throws MyException {
        curriculumService.delete(id);
        return new Result().success();
    }

    @RequestMapping("/listPage")
    public Result listPage(Page page, @RequestParam Map<String,Object> params) throws MyException {
        IPage resPage = curriculumService.listPage(page,params);
        return new Result().success().setData(resPage);
    }

    @RequestMapping("/list")
    public Result list(@RequestBody Map<String,Object> params) throws MyException {
        List<Curriculum> list = curriculumService.list(params);
        return new Result().success().setData(list);
    }

    @RequestMapping("/all")
    public Result all(){
        List<Curriculum> list = curriculumService.all();
        return new Result().success().setData(list);
    }

}
